using System;
using System.Collections.Generic;
using System.Linq;
using System.ComponentModel;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content.Pipeline;
using Microsoft.Xna.Framework.Content.Pipeline.Graphics;
using Microsoft.Xna.Framework.Content.Pipeline.Processors;
using Microsoft.Xna.Framework.Graphics.PackedVector;



namespace CustomProcessors
{
    [ContentProcessor(DisplayName = "AdvancedTextureProcessor - Custom")]
    public class AdvancedTextureProcessor : TextureProcessor
    {
        public enum CustomTextureProcessorOutputFormat
        {
            NoChange = 0,
            Color = 1,
            DxtCompressed = 2,
            Gray16 = 3,
        }



        [Browsable(false)]
        public override TextureProcessorOutputFormat TextureFormat { get; set; }

        [Description("Specifies the SurfaceFormat type of processed textures.")]
        [DisplayName("Texture Format")]
        [DefaultValue(CustomTextureProcessorOutputFormat.Color)]
        public virtual CustomTextureProcessorOutputFormat CustomTextureFormat { get; set; }



        public override TextureContent Process(TextureContent input, ContentProcessorContext context)
        {
            if(CustomTextureFormat == CustomTextureProcessorOutputFormat.Gray16)
            {
                TextureFormat = TextureProcessorOutputFormat.Color;
                input = base.Process(input, context);
                input.ConvertBitmapType(typeof(PixelBitmapContent<HalfSingle>));
                return input;
            }
            else if(CustomTextureFormat == CustomTextureProcessorOutputFormat.NoChange)
                TextureFormat = TextureProcessorOutputFormat.NoChange;
            else if(CustomTextureFormat == CustomTextureProcessorOutputFormat.Color)
                TextureFormat = TextureProcessorOutputFormat.Color;
            else if(CustomTextureFormat == CustomTextureProcessorOutputFormat.DxtCompressed)
                TextureFormat = TextureProcessorOutputFormat.DxtCompressed;

            return base.Process(input, context);
        }
    }
}